/*项目工资发放-详情*/
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:frametrim/appviews/timeMarkView.dart';
import 'package:frametrim/appviews/twoTextView.dart';
import 'package:frametrim/utility/screen.dart';
import 'package:frametrim/utility/sq_color.dart';

import '../../appviews/ThreeTextView.dart';
import '../../appviews/lineToTextView.dart';
import '../../utility/log_utils.dart';
import '../../views/appbar_search_toAppbar.dart';
import '../../views/background_view.dart';
import '../../views/mySliverAppBar.dart';

class ProjectSalaryIssueDetailsPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => ProjectSalaryIssueDetailsState();
}

class ProjectSalaryIssueDetailsState
    extends State<ProjectSalaryIssueDetailsPage> {
  //TickerProviderStateMixin
  TextEditingController _controller = TextEditingController();

  late double? expandedHeight = 800;

  final GlobalKey mTop1Key = GlobalKey();
  final GlobalKey mTop2Key = GlobalKey();

  @override
  void initState() {
    super.initState();
    Future.delayed(Duration(milliseconds: 500), () {
      setState(() {
        //topWidget高度+marginTop(10)+MarginBottom(10)+地图(120)+分割(10)+标题高度(45)+目测缺少间隔(5)
        expandedHeight = 45 +
            mTop1Key.currentContext!.size!.height +
            mTop2Key.currentContext!.size!.height;
        LogUtils.e("expandedHeight==${expandedHeight}");
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: SQColor.color_background,
        body: AnnotatedRegion(
          value: SystemUiOverlayStyle.dark,
          child: Column(
            children: [
              AppbarSearchUseAppBarTitle(
                imgStr: 'image/imv_back.png',
                controller: _controller,
                isNeedCenter: false,
                callback: (str) {},
                hiteText: "请输入人员名称",
                isNeedJump: false,
                isShowSearchImg: false,
              ),
              Expanded(
                  child: NestedScrollView(
                      headerSliverBuilder: (context, innerBoxIsScrolled) {
                        return <Widget>[
                          //自定义-取消topPadding
                          MySliverAppBar(
                            backgroundColor: SQColor.color_background,
                            toolbarHeight: 0,
                            //是否固定在顶部
                            pinned: true,
                            //是否随着滑动隐藏标题
                            floating: true,
                            expandedHeight: expandedHeight,
                            // expandedHeight: 700,
                            // toolbarHeight:
                            flexibleSpace: FlexibleSpaceBar(
                              // key: _flexibleSpaceBarKey,
                              //设置标题部分  收缩样式
                              collapseMode: CollapseMode.pin,
                              background: Container(
                                child: Column(
                                  children: [buildTop1(), buildTop2()],
                                ),
                              ),
                            ),
                            bottom: PreferredSize(
                              preferredSize: Size(Screen.width - 24, 45),
                              child: buildTableWidget(),
                            ),
                          )
                        ];
                      },
                      body: Container(
                        height: double.infinity,
                        margin: EdgeInsets.only(left: 10, right: 10),
                        padding: EdgeInsets.only(left: 10, right: 10),
                        decoration: BoxDecoration(
                            borderRadius: BorderRadius.only(
                                bottomLeft: Radius.circular(8),
                                bottomRight: Radius.circular(8)),
                            color: SQColor.white),
                        child: /*Flexible(
                            child:*/
                            ListView.builder(
                                padding: EdgeInsets.only(top: 0),
                                // shrinkWrap: true,
                                itemBuilder: (context, index) {
                                  return buildItem();
                                },
                                itemCount: 20),
                      )))
              // )
            ],
          ),
        ));
  }

/*顶部-项目信息*/
  Widget buildTop1() {
    return BackgroundView(
      globalKey: mTop1Key,
      mHorizontalMargin: 12,
      mHorizontalPadding: 0,
      mVerticalPadding: 0,
      widget: Stack(
        children: [
          Align(
              alignment: Alignment.topRight,
              child: TimeMarkView(text: '2022年9月')),
          Container(
            margin: EdgeInsets.only(left: 10, top: 10, bottom: 10),
            child: Column(
              children: [
                Container(
                    margin: EdgeInsets.only(right: 100),
                    child: LineToTextView(
                        text1: "郑州市金水区陈砦城中村改造",
                        textSize: 16,
                        isBind: true,
                        textColor: SQColor.color_90black)),
                Row(
                  children: [
                    Text('中原区',
                        style: TextStyle(
                            fontSize: 14, color: SQColor.color_60black)),
                    SizedBox(width: 30),
                    Text('房屋建筑施工工程',
                        style: TextStyle(
                            fontSize: 14, color: SQColor.color_60black)),
                  ],
                ),
                SizedBox(height: 20),
                Row(
                  children: [
                    Expanded(
                        child: Text('施工单位',
                            style: TextStyle(
                                fontSize: 14, color: SQColor.color_60black))),
                    Text('河南九九建筑工程有限公司',
                        style: TextStyle(
                            fontSize: 14, color: SQColor.color_60black)),
                    SizedBox(width: 10),
                  ],
                ),
                SizedBox(height: 10),
                Row(
                  children: [
                    Expanded(
                        child: Text('工资代发银行',
                            style: TextStyle(
                                fontSize: 14, color: SQColor.color_60black))),
                    Text('建设银行桐柏路支行',
                        style: TextStyle(
                            fontSize: 14, color: SQColor.color_60black)),
                    SizedBox(width: 10),
                  ],
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }

  /*顶部-工资信息*/
  Widget buildTop2() {
    return BackgroundView(
        globalKey: mTop2Key,
        mHorizontalMargin: 12,
        mHorizontalPadding: 10,
        mVerticalTopMargin: 0,
        mVerticalBottomMargin: 10,
        mVerticalPadding: 10,
        widget: Column(
          children: [
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                TwoTextView(text1: '569.58', text2: '应核算人数'),
                TwoTextView(text1: '569.58', text2: '已核算人数'),
                TwoTextView(text1: '569.58', text2: '已付工资人数'),
              ],
            ),
            SizedBox(height: 20),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                ThreeTextView(
                  text1: '569.58',
                  text2: '应付工资',
                  text3: '总额（万元）',
                ),
                ThreeTextView(text1: '569.58', text2: '已付工资', text3: '总额（万元）'),
                ThreeTextView(text1: '569.58', text2: '未付工资', text3: '总额（万元）'),
              ],
            ),
          ],
        ));
  }

  /*悬浮部分*/
  Widget buildTableWidget() {
    return Container(
      height: 45,
      margin: EdgeInsets.only(left: 12, right: 12),
      padding: EdgeInsets.only(left: 10, right: 10),
      decoration: BoxDecoration(
        borderRadius: BorderRadius.only(
            topLeft: Radius.circular(10), topRight: Radius.circular(10)),
        color: SQColor.color_EBEDF1,
      ),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Expanded(
              child: Text('姓名',
                  style: TextStyle(fontSize: 14, color: SQColor.color_222222))),
          Expanded(
              child: Text('考勤天数',
                  style: TextStyle(fontSize: 14, color: SQColor.color_222222))),
          Expanded(
              child: Text('当月应付',
                  style: TextStyle(fontSize: 14, color: SQColor.color_222222))),
          Expanded(
              child: Text('发放进度',
                  style: TextStyle(fontSize: 14, color: SQColor.color_222222))),
        ],
      ),
    );
  }

  /*item*/
  Widget buildItem() {
    return Column(
      children: [
        Container(
            padding: EdgeInsets.symmetric(vertical: 5),
            child: Row(children: [
              Expanded(
                  child: Text('任瑞堂',
                      style:
                      TextStyle(fontSize: 14, color: SQColor.color_222222))),
              Expanded(
                  child: Text('18',
                      style:
                      TextStyle(fontSize: 14, color: SQColor.color_222222))),
              Expanded(
                  child: Text('32135.89',
                      style:
                      TextStyle(fontSize: 14, color: SQColor.color_222222))),
              Expanded(
                  child: Text('待主管部门审核',
                      style:
                      TextStyle(fontSize: 14, color: SQColor.color_222222))),
            ])),
        Divider(height: 1, color: SQColor.color_DEDEDE)
      ],
    );

  }
}
